package com.pw.canbuslogger.view;

import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JTabbedPane;

import com.pw.canbuslogger.CANBusDataReader;
import com.pw.canbuslogger.CANBusDataWriter;

import java.awt.BorderLayout;
import java.util.concurrent.ConcurrentLinkedQueue;

public class MainWindow {

    private JFrame frame;

    /**
     * Launch the application.
     */
    public static void main(String[] args) {
        EventQueue.invokeLater(new Runnable() {

            public void run() {
                try {
                    MainWindow window = new MainWindow();
                    window.frame.setVisible(true);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
    }

    /**
     * Create the application.
     */
    public MainWindow() {
        initialize();
    }

    /**
     * Initialize the contents of the frame.
     */
    private void initialize() {
        frame = new JFrame();
        frame.setBounds(100, 100, 767, 555);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.TOP);
        frame.getContentPane().add(tabbedPane, BorderLayout.CENTER);

        CANBusGridViewPanel canBusGridViewPanel = new CANBusGridViewPanel();
        tabbedPane.add("Grid View", canBusGridViewPanel);
        tabbedPane.setEnabledAt(0, true);

        ConcurrentLinkedQueue<Object[]> queue = new ConcurrentLinkedQueue<Object[]>();

        Runnable reader = new CANBusDataReader(queue);
        Runnable writer = new CANBusDataWriter(queue, canBusGridViewPanel);

        new Thread(reader).start();
        new Thread(writer).start();

    }

}
